package com.clas.liu.myapplication.presenter.impl;

import android.os.Handler;
import android.os.Message;

import com.clas.liu.myapplication.model.entity.Register.RegisterRoot;
import com.clas.liu.myapplication.model.entity.user.UserData;
import com.clas.liu.myapplication.model.event.RegisterEvent;
import com.clas.liu.myapplication.model.impl.RegisterModel;
import com.clas.liu.myapplication.presenter.i.IRegisterPresenter;
import com.clas.liu.myapplication.view.activity.impl.RegisterActivity;

/**
 * Created by liu on 2019/4/25.
 */

public class RegisterPresenter extends BasePresenter<RegisterActivity, RegisterModel> implements IRegisterPresenter {
    public RegisterPresenter(RegisterActivity view) {
        super(view);
    }

    @Override
    public void register(UserData userData, String pwd) {
        mModel.register(userData, pwd);
    }

    @Override
    public void registerReturn() {

    }

    @Override
    protected RegisterModel getModel(Handler handler) {
        return new RegisterModel(handler);
    }

    @Override
    protected void eventReceive(Message msg) {
        switch (msg.what) {
            case RegisterEvent.REGISTER_OK:
                RegisterRoot root = ((RegisterEvent) msg.obj).getRegisterRoot();
                mView.registerReturn(root.getCode(),root.getMessage());
                break;
            case RegisterEvent.REGISTER_FAIL:
                mView.failBecauseNetReturn(msg.what);
                break;
        }
    }
}
